﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using CrystalDecisions.Windows;

namespace QLThuoc_report
{
    public partial class In_HoaDon : Form
    {
        public In_HoaDon()
        {
            InitializeComponent();
        }
        private int _maHoaDon;

        public int MaHoaDon
        {
            get { return _maHoaDon; }
            set { _maHoaDon = value; }
        }
        private void In_HoaDon_Load(object sender, EventArgs e)
        {
            txt_MaHoaDon.Text = MaHoaDon.ToString();
            txt_MaHoaDon.Hide();
            SqlConnection
            conn = new SqlConnection("Data Source =(local);Initial Catalog=QLThuoc;Integrated Security=true");
            SqlDataAdapter da = new SqlDataAdapter("SELECT     dbo.tbl_CTHoaDonBH.MaHDBH AS [Mã Hóa Đơn], dbo.tbl_HoaDonBH.TenHD AS [Tên Hóa Đơn], dbo.tbl_KhachHang.TenKH AS [Tên Khách Hàng],   dbo.tbl_KhachHang.DiaChi AS [Địa Chỉ], dbo.tbl_CTHoaDonBH.MaThuoc AS [Mã Thuốc], dbo.tbl_Thuoc.TenThuoc AS [Tên Thuôc],   dbo.tbl_CTHoaDonBH.SoLuong AS [Số Lượng], dbo.tbl_Thuoc.GiaTien AS [Giá Tiền],  dbo.tbl_CTHoaDonBH.SoLuong * dbo.tbl_Thuoc.GiaTien * 10 / 100 + dbo.tbl_CTHoaDonBH.SoLuong * dbo.tbl_Thuoc.GiaTien AS [Thành Tiền],    dbo.tbl_CTHoaDonBH.NgayBan AS [Ngày Bán], dbo.tbl_CTHoaDonBH.GhiChu AS [Ghi Chú], dbo.tbl_NhanVien.HoTen AS [Nhân Viên Bán Hàng] FROM         dbo.tbl_CTHoaDonBH INNER JOIN dbo.tbl_HoaDonBH ON dbo.tbl_CTHoaDonBH.MaHDBH = dbo.tbl_HoaDonBH.MaHDBH INNER JOIN  dbo.tbl_KhachHang ON dbo.tbl_HoaDonBH.MaKH = dbo.tbl_KhachHang.MaKH INNER JOIN  dbo.tbl_NhanVien ON dbo.tbl_HoaDonBH.MaNV = dbo.tbl_NhanVien.MaNV INNER JOIN  dbo.tbl_Thuoc ON dbo.tbl_CTHoaDonBH.MaThuoc = dbo.tbl_Thuoc.MaThuoc where tbl_CTHoaDonBH.MaHDBH='"+txt_MaHoaDon.Text+"'", conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            //lay duong dan du chuy?n sang máy tính nào c?ng ko b? l?i, ko có c?ng ðc nhýng sang máy tính khác s? ko ch?y ðc
            string path = Application.StartupPath;
            path = path.Substring(0, path.LastIndexOf("bin")) + "HoaDonBanHang.rpt";
            HoaDonBanHang report = new HoaDonBanHang();
            report.SetDataSource(dt);
            crystalReportViewer1.ReportSource = report;
        }
    }
}
